<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Web Storage</title>
  <link rel="stylesheet" href="./demo.css">
</head>

<body>
  <div id="app">
    <div class="btn" @click="saveLocalStorage">localStorage存储</div>
    <div class="btn" @click="getLocalStorage">localStorage获取</div>
    <div class="btn" @click="deleteLocalStorage">localStorage删除</div>

    <div class="btn" @click="saveSessionStorage">sessionStorage存储</div>
    <div class="btn" @click="getSessionStorage">sessionStorage获取</div>
    <div class="btn" @click="deleteSessionStorage">sessionStorage删除</div>

    <div>{{storage}}</div>
  </div>
  <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
  <script>
    let app = new Vue({
      el: '#app',
      data: {
        storage: ''
      },
      methods: {
        saveLocalStorage() {
          window.localStorage.setItem('key', 'value')
        },
        getLocalStorage() {
          this.storage = window.localStorage.getItem('key')
        },
        deleteLocalStorage() {
          window.localStorage.removeItem('key')
        },
        saveSessionStorage() {
          window.sessionStorage.setItem('key', 'value')
        },
        getSessionStorage() {
          this.storage = window.sessionStorage.getItem('key')
        },
        deleteSessionStorage() {
          window.sessionStorage.removeItem('key')
        }
      }
    })
  </script>
</body>

</html>